package com.zcxy360.sandtable.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zcxy360.sandtable.domain.CourseStage;
import com.zcxy360.sandtable.domain.CourseStageMapper;

@Transactional
@Service
public class CourseStageService {

	@Autowired
	private CourseStageMapper courseStageMapper;
	
	public CourseStage getByStageId(Integer stageId) {
		return courseStageMapper.selectByPrimaryKeyWithCascade(stageId);
	}

	public List<CourseStage> listByCourseId(Integer courseId) {
		return courseStageMapper.listByCourseId(courseId);
	}
	
	public  boolean update(CourseStage courseStage) {
		return courseStageMapper.updateByPrimaryKeySelective(courseStage) == 1;
	}

	public Object startTeamStage(Integer courseId, boolean keep) {
		int userNoRole = courseStageMapper.startTeamStage(courseId,keep);
		if(userNoRole != 0) {
			throw new RuntimeException("有学员未分配角色,无法开启后续课程");
		}
		return true;
	}

}
